// pages/homePage/homePage.js
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    choose2_modal:'none',
    type:1,
   index:0
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // this.getUserLocation();
    //获取手机高度
    this.setData({
      navH: app.globalData.navHeight,
      price:options.price,
      orderList:options.orderList
    })
    this.getAddress();
  },
  /**
   * 页面分享
   */
  onShareAppMessage: function () {
    var that = this;
    return {
      title: that.data.title,
      desc: '分享页面的内容',
      imageUrl: "http://file.jwsxmall.com/shareImg.jpg",
      path: '/pages/homePage/homePage?partnerUserId=' + wx.getStorageSync("userId") + '&type=2', // 路径，传递参数到指定页面
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var that = this;

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },


  navBack: function () {
    wx.navigateBack({

    })
  },
  choose: function (e) {
      this.setData({
        type: e.currentTarget.dataset.type
      })
  },
  chooseFress: function () {
    this.setData({
      choose2_modal: 'block'
    })
  },
  modal_none: function () {
    this.setData({
      choose2_modal: 'none'
    })
  },
  goMore: function () {
    if (this.data.countTextList!=undefined){
      wx.navigateTo({
        url: '/pages/issusInvoice/issusInvoice?c1=' + this.data.countTextList[0] + '&c2=' + this.data.countTextList[1] + '&c3=' + this.data.countTextList[2],
      })
    }else{
      wx.navigateTo({
        url: '/pages/issusInvoice/issusInvoice'
      })
    }
  },
  chooseAddr: function (e) {
    var index = e.currentTarget.dataset.index;
    this.setData({
      index:index
    })
  },
  getAddress: function () {
    var that = this;
    wx.request({
      url: app.globalData.url + "getUserAddressList",
      data: {
        userId: wx.getStorageSync("userId"),
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        that.setData({
          addressList: res.data.data
        })
      },
    })

  },
  gethead: function (e) {
    var text = e.detail.value;
    this.setData({
      content: text
    })
  },
  getInv: function (e) {
    var text = e.detail.value;
    this.setData({
      taxNo: text
    })
  },
  trueShen: function (e) {
    var that = this;
    if(that.data.countTextList!=undefined){
      wx.request({
        url: app.globalData.url + "applyOrderInvoce",
        data: {
          userId: wx.getStorageSync("userId"),
          type: that.data.type,
          content: that.data.content,
          taxNo: that.data.taxNo,
          materialType: 1,
          address: that.data.addressList[that.data.index].wholeAddress,
          remark: that.data.countTextList[0] + that.data.countTextList[1] + that.data.countTextList[2],
          orderList: that.data.orderList
        },
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
          if (res.data.result == 0) {
            wx.showToast({
              title: res.data.errmsg,
              icon: 'none'
            })
          } else {
            wx.navigateTo({
              url: '/pages/invoiceApplicationSuccess/invoiceApplicationSuccess',
            })
          }
        },

      })
    }else{
      wx.request({
        url: app.globalData.url + "applyOrderInvoce",
        data: {
          userId: wx.getStorageSync("userId"),
          type: that.data.type,
          content: that.data.content,
          taxNo: that.data.taxNo,
          materialType: 1,
          address: that.data.addressList[that.data.index].wholeAddress,
          remark: '',
          orderList:that.data.orderList
        },
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
          if (res.data.result == 0) {
            wx.showToast({
              title: res.data.errmsg,
              icon: 'none'
            })
          } else {
            wx.navigateTo({
              url: '/pages/invoiceApplicationSuccess/invoiceApplicationSuccess',
            })
          }
        },

      })
    }

  },
})